import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/user/address/manage/controller.dart';
import 'package:flutter_jd/tools/utils/library.dart';
import 'package:flutter_jd/ui/widgets/body/top_bar.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/get.dart';

// 地址管理
class AddressManage extends GetView<AddressManageController> {
  @override
  Widget build(BuildContext context) {
    Get.put(AddressManageController());
    List messageList = controller.messageList;

    return Scaffold(
      backgroundColor: Color(0xFFF5F5F5),
      appBar: TopBar(
        title: '地址管理',
        isBack: true,
      ),
      body: Column(
        children: [
          Expanded(
            child: ListView.builder(
              itemCount: messageList.length,
              itemBuilder: (BuildContext context, int index) {
                Map item = messageList[index];

                return Container(
                  margin: EdgeInsets.only(top: index == 0 ? 8.h : 0),
                  child: Ink(
                    decoration: BoxDecoration(
                      color: Colors.white,
                    ),
                    child: InkWell(
                      onTap: () {},
                      child: Container(
                        padding: EdgeInsets.symmetric(
                          horizontal: 12.w,
                        ),
                        decoration: BoxDecoration(
                          border: Border(
                            bottom: BorderSide(
                              color: Color(0xFFF5F5F5),
                              width: 1,
                            ),
                          ),
                        ),
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Expanded(
                              child: Container(
                                padding: EdgeInsets.only(
                                  left: 12.w,
                                  top: 12.h,
                                  bottom: 12.h,
                                ),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    Row(
                                      children: [
                                        Container(
                                          width: 30.w,
                                          alignment: Alignment.center,
                                          decoration: BoxDecoration(
                                            color: Color(0xFF4B87FF),
                                            borderRadius:
                                                BorderRadius.circular(3.r),
                                          ),
                                          padding:
                                              EdgeInsets.symmetric(vertical: 1),
                                          margin: EdgeInsets.only(right: 10.w),
                                          child: Text(
                                            item['label'],
                                            style: TextStyle(
                                              color: Colors.white,
                                              fontSize: 10.sp,
                                            ),
                                          ),
                                        ),
                                        Text(
                                          item['address'],
                                          maxLines: 1,
                                          overflow: TextOverflow.ellipsis,
                                          style: TextStyle(
                                            color: Color(0xFF888888),
                                            fontSize: 12.sp,
                                          ),
                                        ),
                                      ],
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(top: 5.h),
                                      child: Text(
                                        item['detail'],
                                        maxLines: 2,
                                        overflow: TextOverflow.ellipsis,
                                        style: TextStyle(
                                          color: Color(0xFF333333),
                                          fontSize: 14.sp,
                                          fontWeight: FontWeight.w600,
                                        ),
                                      ),
                                    ),
                                    Row(
                                      children: [
                                        Container(
                                          width: 115.w,
                                          margin: EdgeInsets.only(top: 5.h),
                                          child: Text(
                                            item['name'],
                                            maxLines: 2,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: Color(0xFF888888),
                                              fontSize: 13.sp,
                                            ),
                                          ),
                                        ),
                                        Container(
                                          margin: EdgeInsets.only(top: 3.h),
                                          child: Text(
                                            item['mobile'],
                                            maxLines: 2,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: Color(0xFF888888),
                                              fontSize: 13.sp,
                                            ),
                                          ),
                                        ),
                                      ],
                                    )
                                  ],
                                ),
                              ),
                            ),
                            Container(
                              width: 50,
                              height: 50,
                              child: Kit.iconFont(
                                  0xe850, Color(0xFF333333), 16.sp),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                );
              },
            ),
          ),
          Container(
            width: double.infinity,
            padding: EdgeInsets.only(
              bottom: Utils.getBottomHeight(),
              left: 15.w,
              right: 15.w,
            ),
            child: Container(
              height: 40.h,
              child: Ink(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [
                      Color(0xFFFA2F19),
                      Color(0xFFFA722E),
                    ],
                  ),
                  borderRadius: BorderRadius.circular(30.r),
                ),
                child: InkWell(
                  borderRadius: BorderRadius.circular(30.r),
                  splashColor: Color(0xFFFA2F19),
                  onTap: () {
                    // _submit();
                  },
                  child: Container(
                    width: 300.w,
                    height: 40.h,
                    alignment: Alignment.center,
                    child: Text(
                      '新建收货地址',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 14.sp,
                      ),
                    ),
                  ),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
